<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
 <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<style>
	.error-text{
		line-height: 20px;
		font-size:14px;
		color: rgb(209, 91, 71);
	}
</style>
<script type="text/dialog">
	var  roleBox = document.getElementsByName("roleIds");
	var  userRole = '${puser.roleIds}';
	var  roles = userRole.split(',');
	for(i =0 ; i<roleBox.length; i++){
		for(j = 0;j<roles.length;j++){
			if(roleBox[i].value == roles[j]){
				roleBox[i].checked = 'true';
				break;
			}
		}
	}
	$('#userEditForm').validate({
	 errorElement: 'div',
     errorClass: 'help-block',
     focusInvalid: false,
     rules: {
          realname:{
               required:true
          },
		mobile:{
			phone:true
		}
     },
	highlight: function (e) {          //错误信息高亮显示，可自由配置
          $(e).closest('.form-group').removeClass('has-info').addClass('has-error');          
     },
     success: function (e) {          //验证成功执行表单提交
          $(e).closest('.form-group').removeClass('has-error');//.addClass('has-info');
          $(e).remove();
     },
	submitHandler: function(form) {   //Ajax提交用$(form),如果是普通提交的话就直接用form，目前原理不明
		$(form).ajaxSubmit({
			beforeSubmit: showRequest,
			success:       showResponse
		});
     }, 
     errorPlacement: function(error, element) {     //错误信息显示位置
		if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
			error.appendTo(element.parent().parent());
		} else {
			error.insertAfter(element);
		}
     }
	});

function showRequest(formData, jqForm, options){
 	var queryString = $.param(formData);
 	art.dialog({id:'uploadDialog',title:'正在处理...',content:'<img src="../resources/admin/assets/images/loading2.gif">&nbsp;&nbsp;处理中，请稍后...',width:'250px',height:'120px',lock:true,background:'#ccc'});
 	return true;
 }
 function showResponse(data){
 	art.dialog.list['uploadDialog'].close();
 	<%--var data = eval('(' + data + ')');--%>
 	if(data.success){
 		$(".error-text").html("");
		art.dialog({id:'userEditDialog'}).close();
		art.dialog({content:data.msg,resize:true,time:2,icon:'succeed',ok:function(){this.close()}});
		$('#UserTable').DataTable().draw() ;		//重新刷新数据表格
 	}else{
 		$(".error-text").html(data.msg);
		return;
 	}
 }
</script>
<div class="scheduleBox">
	<h3 class="lighter block green">编辑管理员</h3>
	<form class="form-horizontal" role= "form" id="userEditForm" name="userEditForm" method="post" action="${pageContext.request.contextPath}/sys/user/userEdit.do">
		<input type="hidden" name="id" value="${puser.id}">
		<div class="form-group">
			<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 账号: </label>
			<div class="col-sm-8">
				<input type="text" id="title" class="col-sm-6" name="username" value="${puser.username}" readonly="readonly"/>
			</div>
		</div>
		
		<div class="form-group">
			<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 密码: </label>
			<div class="col-sm-8 ">
				<input type="text"  class="col-sm-6"  name="password" />
				<span class="col-sm-6 red">密码留空即保持原密码一致.</span>
			</div>
		</div>
		
		<div class="form-group">
			<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 姓名: </label>
			<div class="col-sm-8 ">
				<input type="text"  class="col-sm-6" id="realname" name="realname" value="${puser.realname}"/>
			</div>
		</div>
		
		<div class="form-group">
			<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 手机号码: </label>
			<div class="col-sm-8 ">
				<input type="text"  class="col-sm-6" id="mobile" name="mobile" value="${puser.mobile}"/>
			</div>
		</div>
		
		<div class="form-group">
			<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 人员备注: </label>
			<div class="col-sm-8 ">
				<input type="text"  class="col-sm-12" id="remarks" name="remarks" value="${puser.remarks}"/>
			</div>
		</div>
		
		<div class="form-group">
			<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 所属角色: </label>
			<div class="col-sm-8 ">
				<c:forEach var="roleList" items="${roleList}">
					<label>
						<input name="roleIds" type="checkbox" class="ace" value="${roleList.id}" />
						<span class="lbl"> ${roleList.rolename}</span>
					</label>
				</c:forEach>
				
			</div>
		</div>
		
		<div class="form-group">
			<div class="col-sm-4">
				<button type="submit" class="btn btn-sm btn-success" >
				保存
				<i class="ace-icon fa fa-pencil bigger-110"></i>
				</button>
			</div>
		</div>
		
	</form>
</div>